/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package traditioanl_client;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;


/**
 *
 * @author Teva
 */
public class Traditioanl_Client 
{

    /**
     * @param args the command line arguments
     */
    
    Socket socket = null;
    
    public static void main(String[] args) throws UnknownHostException, IOException 
     {
       
        int port = 5000;
        
	String server = "localhost";
        
	Traditioanl_Client obj= new Traditioanl_Client();	
	        
	obj.setupServer(port, server);
        
	obj.fileTransfer();	         
	
    }
    
    protected void setupServer(int port,String server) throws UnknownHostException, IOException
    {
       	
        socket = new Socket(server, port);
              
        System.out.println("Connected with server " + socket.getInetAddress() +  ":" + socket.getPort());
    }
    
      protected void fileTransfer() throws IOException 
     {
        FileInputStream inputStream = null;
         
        String fname = "C:/JavaExample/File1.txt";
		
        inputStream = new FileInputStream(fname);  
        
        DataOutputStream output= null;
         
        output = new DataOutputStream(socket.getOutputStream());
           
           byte[] b = new byte[4096];
            
	    long read = 0, total = 0;
            
            long start = System.currentTimeMillis();
            
	    while((read = inputStream.read(b))>=0) 
            {
		total = total + read;
	    	output.write(b);
	    }
            
	   System.out.println("total bytes transferred--"+total+" and time taken in MS----"+(System.currentTimeMillis() - start));
           
           inputStream.close();
           output.close();
           socket.close();
     }
}
